﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SimpleGame.ScreenManagement.Screens
{
    public class PauseMenuScreen : MenuScreen
    {
        #region Fields
        
        // The parent screen this pause screen is attached to
        private GameScreen parentScreen;

        #endregion

        #region Constructor

        public PauseMenuScreen(GameScreen parentScreen)
            : base("Pause")
        {
            this.parentScreen = parentScreen;

            // Create menu items
            MenuItem resumeMenuItem = new MenuItem("Resume");
            MenuItem quitGameMenuItem = new MenuItem("Quit Game");

            // Hook up menu event handlers
            resumeMenuItem.Selected += OnCancel;
            quitGameMenuItem.Selected += QuitGameMenuItemSelected;

            // Add items to the menu
            menuItems.Add(resumeMenuItem);
            menuItems.Add(quitGameMenuItem);
        }

        #endregion

        #region Event Handlers

        /// <summary>
        /// When the user cancels the main menu, the game continues.
        /// </summary>
        protected override void OnCancel(object sender, EventArgs e)
        {
            screenManager.RemoveScreen(this);
            parentScreen.IsActive = true;
            parentScreen.IsHidden = false;
        }

        /// <summary>
        /// Event handler for when the Quit Game menu item is selected.
        /// </summary>
        private void QuitGameMenuItemSelected(object sender, EventArgs e)
        {
            screenManager.AddScreen(new MainMenuScreen());
            screenManager.RemoveScreen(parentScreen);
            screenManager.RemoveScreen(this);
        }

        #endregion
    }
}
